package com.itheima.model.vo;

import com.itheima.model.domain.Options;
import com.itheima.model.domain.Questions;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class QuestionsVo implements Serializable {
    private String id;//问卷编号
    private String question;//问卷名称
    private List<OptionsVo> options;//试题


    public static QuestionsVo init(Questions rQuestion,List<Options> rOptions){
        QuestionsVo questionsVo = new QuestionsVo();
        questionsVo.setId(rQuestion.getId().toString());
        questionsVo.setQuestion(rQuestion.getQuestion());
        //设置options参数
        List<OptionsVo> options1=new ArrayList<>();
        for (Options rOption : rOptions) {
            options1.add(OptionsVo.init(rOption));
        }
        questionsVo.setOptions(options1);
        return questionsVo;
    }
}